<template>
	<view class="box">
		

		<view class="menu_content_box_page">

			<video :src="url" style="width: 100%;" :controls="true" :autoplay="true"></video>
		</view>
		
	</view>
</template>
<script>
	import {
		toast,
		showLoading,
		hideLoading
	} from '@/utils/toast.js';
	import {
		getDatumDetailPageApi,
		getDatumUrlApi,
		getVideoUrlApi,
		getHtmlContentApi
	} from '@/http/api.js';

	export default {
		data() {
			return {
				html: '',
				url: '',
				id: 0,
				beVideo: true,
				userId: uni.getStorageSync('userId'),
				title: ''
			}
		},
		onLoad(options) {
			console.log(options, 99999);
			if (!options.id) {
				toast('参数不正确！');
			}
			this.id = options.id;
			this.title = options.title;
			if (options.beVideo) {
				this.beVideo = options.beVideo;
			}
			if (this.title) {
				uni.setNavigationBarTitle({
					title: this.title
				})
			}
			this.getVideoUrl();

			
		},
		methods: {
			back() {
				uni.navigateBack({
					delta: 1
				})
			},
			
			getVideoUrl() {
				let that = this;
				showLoading('加载中');
				getVideoUrlApi({
					userId: uni.getStorageSync('userId'),
					id: this.id
				}).then(res => {
					let url = res.data;
					that.url = url;
					hideLoading();
				}).catch(err => {
					hideLoading();
				})
			},
			
			getDatumDetailPage() {
				let that = this;
				showLoading('加载中');
				getDatumDetailPageApi({
					id: this.id,
					userId: this.userId
				}).then(res => {
					that.detail = res.data;
					that.beVideo = res.data.beVideo;
					if (that.detail.beVideo) {
						that.getVideoUrl();
					} else {
						that.getHtmlContent();
					}
				}).catch(err => {
					toast(err.msg);
					hideLoading();
				})
			},

			

			getHtmlContent() {
				let that = this;
				showLoading('加载中');
				getHtmlContentApi({
					userId: uni.getStorageSync('userId'),
					id: this.id
				}).then(res => {
					that.html = res.data;
					console.log(that.html)
					hideLoading();
				}).catch(err => {
					hideLoading();
				})
			},

			preview(src, e) {
				// do something
			},
			navigate(href, e) {
				// do something
			}
		}
	}
</script>

<style>
	.menu_content_box_page {
		position: relative;
		background-color: #f7f6f6;
		padding-top: 177rpx;
	}

	.search_box {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		padding: 85rpx 24rpx 25rpx;
		background-color: #fff;
		z-index: 3;
	}
</style>
